<template>
	<div class="adminMain" v-loading="load.load">
		<el-form class="form" label-position="top" v-if="info">
		    <div class="form-item" v-for="(item, index) in info" :key="index">
				<div class="title">{{ item.title }}</div>
				<el-row :gutter="25">
					<el-col :span="4" v-for="(v, i) in item.items" :key="i">
						<div class="grid-content bg-purple">
							<el-form-item :label="v.title">
								<div class="flex _itemSet">
									<el-input :disabled="v.disabled" v-model="v.value"></el-input>
								</div>
							</el-form-item>
						</div>
					</el-col>
				</el-row>
		    </div>
		    <el-form-item style="margin-top:40px;">
		        <el-button type="primary" @click="save">立即保存</el-button>
		    </el-form-item>
		</el-form>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				
				// 是否处于加载中
				load: { load: false },
				
				// 基本信息
				info: null,
				
			};
		},
		methods: {
			
			// 上传文件
			fileUpload(res, infoIndex, itemIndex, i){
				let _this = this;
				_this.app.uploadFile({ file: res.file, type: "admin", load: _this.load }).then((res) => {
					_this.info[infoIndex].items[itemIndex].value[i].img = res.data.url;
				});
			},
			
			// 获取配置
			getData() {
				let _this = this;
				_this.info = [
					{
						"id": 2,
						"title": "AI配置",
						"sort": 1,
						"items": [
							{
								"id": 48,
								"category_id": 2,
								"key": "ai_default_system",
								"title": "免费试用次数",
								"type": "string",
								"value": "1"
							},
							{
								"id": 48,
								"category_id": 2,
								"key": "ai_default_system",
								"title": "会员每日次数",
								"type": "string",
								"value": "10"
							},
							{
								"id": 48,
								"category_id": 2,
								"key": "ai_default_system",
								"title": "可输入提示词最大长度",
								"type": "string",
								"value": "200"
							},
							{
								"id": 48,
								"category_id": 2,
								"key": "ai_default_system",
								"title": "可选风格",
								"type": "string",
								"value": "随机,流行音乐,摇滚音乐"
							},
							{
								"id": 48,
								"category_id": 2,
								"key": "ai_default_system",
								"title": "热门搜索词",
								"type": "string",
								"value": "随机,流行音乐,摇滚音乐"
							},
						]
					},
					{
						"id": 3,
						"title": "基本配置",
						"sort": 2,
						"items": [
							{
								"id": 45,
								"category_id": 3,
								"key": "sign_urls",
								"title": "无需签名验证URL",
								"type": "json",
								"value": "[\"InviteController\/web\",\"AiVoiceToTextController\/callback\",\"AiCreativeController\/callback\",\"BasisController\/upload\",\"BasisController\/download\",\"AiVideo\/callback_img\",\"AiVideo\/callback_video\",\"PaymentNotifyController\/alipay\",\"PaymentNotifyController\/apple\",\"PaymentNotifyController\/apple_test\",\"PaymentNotifyController\/apple_pay_handle\",\"WechatNotifyController\/no_1671522138\",\"WechatNotifyController\/refund_no_1671522138\",\"WechatNotifyController\/handleNotify\",\"WechatNotifyController\/handleRefundNotify\",\"MarketController\/vivoBack\",\"MarketController\/huaweiBack\",\"MarketController\/honorBack\",\"VipController\/buy\",\"VipController\/applePay\",\"VipController\/applePayRecover\"]"
							},
							{
								"id": 46,
								"category_id": 3,
								"key": "sign_params",
								"title": "签名Header参数",
								"type": "json",
								"value": "[\"Content-type\",\"requesturl\",\"content-type\",\"appversion\", \"productcode\", \"time\", \"language\", \"ua\", \"systemtype\", \"system\", \"packagename\", \"channel\", \"deviceid\", \"brand\", \"version\", \"oaid\",\"authorization\"]"
							},
							{
								"id": 47,
								"category_id": 3,
								"key": "is_open_sign_check",
								"title": "签名认证开关",
								"type": "switch",
								"value": "0"
							},
							{
								"id": 7,
								"category_id": 3,
								"key": "customer_service",
								"title": "联系客服配置",
								"type": "json",
								"value": "{\"corpid\":\"ww92e6d4cadd5947ab\",\"url\":\"https:\/\/work.weixin.qq.com\/kfid\/kfc65b6032db432da19\"}"
							},
							{
								"id": 13,
								"category_id": 3,
								"key": "is_bind_mobile",
								"title": "强绑手机号",
								"type": "json",
								"value": "{ \"channel\": \"xx\", \"effectTime\": \"08:00:00-22:00:00\" }"
							},
							{
								"id": 14,
								"category_id": 3,
								"key": "pay_platform",
								"title": "支持的支付渠道",
								"type": "string",
								"value": "w,a,apple"
							}
						]
					},
				];
				return;
				
				_this.app.ajax({
					url: "/admin/config/index",
					load: _this.load,
					method: "POST",
					success(res) {
						console.log(res.data);
						_this.info = res.data;
					}
				});
			},
			
			// 保存
			save() {
				let _this = this;
				let info = JSON.parse(JSON.stringify(_this.info));
				info.map((item, index) => {
					if(item.id === 5){
						item.items.map((prop, i) => {
							prop.value = JSON.stringify(prop.value);
						})
					}
				});
				
				_this.app.ajax({ 
					url: "/admin/config/update",
					method: "POST",
					data: info,
					load: _this.load,
					success(res) {
						_this.$notify({ message: res.msg, title: "提示", type: "success" });
						_this.getData();
					}
				});
			},
			
		},
		mounted() {
			this.getData();
		}
	};
</script>

<style lang="scss" scoped>
	.adminMain{
		min-height: 500px;
		.form {
			.form-item {
				margin-bottom: 25px;
				.title {
					margin-bottom: 22px;
					.addBannerBtn {
						color: $background;
						font-size: 15px;
						margin-left: 25px;
						display: inline-block;
						margin-top: -2px;
						vertical-align: middle;
						cursor: pointer;
					}
				}
				._itemSet {
					flex-direction: row;
					align-items: center;
					&>a {
						margin-left: 12px;
						cursor: pointer;
						font-size: 18px;
						color: #999;
					}
				}
				.bannerUpload {
					position: relative;
					margin-bottom: 20px;
					.info {
						flex-direction: row;
						margin-top: 12px;
						.input {
							flex: 1;
							width: 0;
		
							&:nth-child(1) {
								margin-right: 13px;
							}
						}
					}
					>>>.el-upload {
						width: 100%;
					}
					.banner_img {
						border-radius: 5px;
						width: 100%;
						height: 150px;
						object-fit: cover;
					}
					.reset {
						cursor: pointer;
						position: absolute;
						right: 0;
						top: 20px;
						z-index: 1;
						font-size: 12px;
						font-style: normal;
						background: rgba(0, 0, 0, 0.2);
						color: #FFF;
						line-height: 26px;
						padding: 0 10px 0 15px;
						border-radius: 15px 0px 0px 15px;
					}
				}
				.wxalipayShow {
					>>>.el-checkbox__input.is-checked+.el-checkbox__label {
						color: #606266;
					}
				}
			}
			.mb-47px {
				margin-bottom: 47px;
			}
			.setTextArea {
				>>>textarea {
					padding: 8px 18px;
					min-height: 40px !important;
					line-height: 20px;
				}
			}
			.uploader-wrapper {
				width: 100%;
				height: 130px;
				border-radius: 6px;
				overflow: hidden;
				cursor: pointer;
				margin-bottom: 10px;
				.upDiv{
					width: 100%;
					height: 100%;
					flex-direction: row;
					align-items: center;
					justify-content: center;
					background: #f6f6f6;
					.addImg2{
						width: 50%;
					}
					.preview-img {
						width: 100%;
						height: 100%;
					}
				}
			}
			.upInfo{
				flex-direction: row;
				align-items: center;
				margin-top: 15px;
				.input{
					flex: 1;
					width: 0;
				}
				.color{
					flex-shrink: 0;
					margin-left: 13px;
				}
			}
			/deep/ .el-upload.el-upload--text {
				width: 100%;
				height: 100%;
			}
		}
	}
</style>